//
//  WSEmoticonPackage.swift
//  emoticonView
//
//  Created by 武莎莎 on 15/9/15.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit
// 三个表情包中需要的共有的属性的模型
class WSEmoticonPackage: NSObject {
    
    // 目录名
    var id: String?
    // 分组的简体中文名
    var group_name_cn:String?
    // 分组中的表情数组
    lazy var emoticons = [WSEmoticons]()
    
    init(dict:[String:AnyObject]) {
        super.init()

        id = dict["id"] as? String
        group_name_cn = dict["group_name_cn"] as? String
        
        if let ems = dict["emoticons"] as? [[String:String]] {
            
            var index = 0
            for var d in ems {
                // 把emoticon数组中的png转化为绝对路径保存，方便以后用
                if let imagePng = d["png"] {
                    d["png"] = id! + "/" + imagePng
                }
                emoticons.append(WSEmoticons(dict:d))
                index++
                
                if index == 20 {
                    emoticons.append(WSEmoticons(isRemove: true))
                    index = 0
                }
            }
        }
        appendBlankCell()
    }
    // 添加空白按钮
    private func appendBlankCell() {
        
        let count = emoticons.count % 21
    
        if count == 0 && emoticons.count > 0 {
            return
        }
        
        for _ in count..<20 {
            emoticons.append(WSEmoticons(isEmpty: true))
        }
        emoticons.append(WSEmoticons(isRemove: true))
    }
    
    override var description:String {
        let keys = ["id","group_name_cn","emoticons"]
        return dictionaryWithValuesForKeys(keys).description
    }
}
